package likouJava;

public class 最大子数组和 {

    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int maxSum = nums[0];     //最大和
        int curSum = nums[0];     //当前和

        for (int i = 1; i < n; i++) {
            //要么加上当前数字，要么重新出发
            curSum = Math.max(nums[i], nums[i] + curSum);
            maxSum = Math.max(curSum, maxSum);
        }
        return maxSum;
    }


}
